package com.herui.iot.ui.evaluation.execute;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.herui.sdyu_lib.base.FragmentDirectionAnim;
import com.herui.sdyu_lib.utils.ToastUtil;
import com.herui.sport_care.R;
import com.herui.sport_care.config.AppConfig;
import com.herui.sport_care.data.SimDataFactory;
import com.herui.sport_care.data.check.DeviceInfo;
import com.herui.sport_care.data.eval.BetaSchemeType;
import com.herui.sport_care.data.eval.EvalInfo;
import com.herui.sport_care.ui.BaseSportFragment;

import butterknife.BindView;
import butterknife.OnClick;

public class EvalChoseFragment extends BaseSportFragment {

    private EvalInfo evalInfo;
    private DeviceInfo ecgDeviceInfo;
    @BindView(R.id.tv_name)
    TextView name;
    @BindView(R.id.tv_agreement)
    TextView agreement;
    @BindView(R.id.tv_time)
    TextView time;

    public static EvalChoseFragment newInstance(EvalInfo evalInfo) {
        EvalChoseFragment fragment = new EvalChoseFragment(evalInfo);
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        setTitle(evalInfo.getName() + "");
        return view;
    }

    public EvalChoseFragment(EvalInfo evalInfo) {
        this.evalInfo = evalInfo;
    }

    @Override
    public int getLayout() {
        return R.layout.fragment_eval_chose;
    }

    @Override
    public void initParam() {
        if (AppConfig.DeviceDebug) {

        }
        ecgDeviceInfo = SimDataFactory.getEcgDeviceInfo();
        ecgDeviceInfo.setMac("EB:F0:91:68:35:71");

        name.setText(evalInfo.getName()+"");
        agreement.setText("协议-"+evalInfo.getAgreementName());
        time.setText(evalInfo.getEvaluationDate() + " " + evalInfo.getEvaluationStartTime());
    }

    @OnClick({R.id.tv_quite, R.id.tv_execute})
    public void onViewClick(View view) {
        Intent intent = null;
        switch (view.getId()) {
            case R.id.tv_quite:
                // 跳转到静息页面
                baseActivity.add(QuietCheckFragment.newInstance(evalInfo, new QuietCheckFragment.FragmentLis() {
                            @Override
                            public void onResult(DeviceInfo ecgDeviceInfo) {
                                EvalChoseFragment.this.ecgDeviceInfo = ecgDeviceInfo;
                            }
                        }),
                        new FragmentDirectionAnim());
                break;
            case R.id.tv_execute:
                // 跳转到执行测试页面
                if (ecgDeviceInfo == null){
                    ToastUtil.showMessage("请先完成静息测试");
                    return;
                }
                BetaSchemeType type = evalInfo.getType();
                if (type.equals(BetaSchemeType.POWER_CAR_LADDER) || type.equals(BetaSchemeType.POWER_CAR_SLOPE)){
                    // 功率车
                    add(PowerExecuteFragment.newInstance(evalInfo, ecgDeviceInfo), new FragmentDirectionAnim());
                }else if (type.equals(BetaSchemeType.TREADMILL_LADDER) || type.equals(BetaSchemeType.TREADMILL_SLOPE)){
                    // 跑台
                    add(TreadmillExecuteFragment.newInstance(evalInfo, ecgDeviceInfo), new FragmentDirectionAnim());
                }
                break;
            default:
                break;
        }
    }

}